home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-04-01 | 5.8 KB | 312 lines | [TEXT/CWIE] |
- #define __NO_LOCATION_MACROS__
- #ifndef __EXCEPTIONS__
- #include "Exceptions.h"
- #endif
- #ifndef __LOCATIONINCODE__
- #include "LocationInCode.h"
- #endif
- #ifndef __DEBUGWRITE__
- #include "DebugWrite.h"
- #endif
- #ifndef __AEBUILD__
- #include "AEBuild.h"
- #endif
-
- #ifndef __OSA__
- #include <OSA.h>
- #endif
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::ThrowAEErr(
- OSStatus err,
- const char* format, ...) const
- {
- StdException exc(*this, err);
-
- if (format != nil)
- {
- va_list arg; va_start(arg, format);
-
- LogIfErr(vAEBuild(&exc.GetErrorParams(), format, arg));
-
- va_end(arg);
- }
-
- exc.AboutToThrow();
- throw exc;
- }
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::Throw(
- OSStatus err) const
- {
- ThrowAEErr(err, nil);
- }
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::Throw(
- OSStatus err, // an error message
- long /* message*/, // MacApp message
- AEKeyword parameter,
- DescType paramType,
- const void* paramData,
- Size paramSize) const
- {
- if (err != noErr)
- {
- AEDesc desc;
-
- desc.descriptorType = typeNull;
- desc.dataHandle = nil;
-
- if (parameter)
- {
- if (LogIfErr(AECreateList(nil, 0, true, &desc)) == noErr)
- {
- LogIfErr(AEPutKeyPtr(&desc, parameter, paramType,
- paramData, paramSize));
- }
- }
-
- Throw(err, &desc);
- }
- }
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::Throw(
- OSStatus err,
- AEDesc* params) const
- {
- StdException exc(*this, err);
-
- if (params != nil)
- {
- exc.GetErrorParams() = *params;
- params->descriptorType = typeNull;
- params->dataHandle = nil;
- }
-
- exc.AboutToThrow();
- throw exc;
- }
-
- //------------------------------------------------------------------------------
-
- /*
-
- void LocationInCode::Throw(
- OSStatus err,
- char* message) const
- {
- Throw(err, 0, keyErrorString, typeChar,
- message, strlen(message));
- }
-
- */
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::ThrowTypeError(
- OSStatus err,
- DescType expectedType) const
- {
- Throw(err, 0, kOSAErrorExpectedType, typeType,
- &expectedType, sizeof(expectedType));
- }
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::ThrowKeywordError(
- OSStatus err, //
- DescType expectedType, // In case of coercion failure, etc.
- const AEDesc& /* desc*/, // Where we were gitting data from
- AEKeyword key) const
- {
- AEKeyword parameter = 0;
- DescType paramType = 0;
- void* paramData = 0;
- Size paramSize = 0;
-
- /// update this •••
-
- switch (err)
- {
- case noErr:
- return;
-
- case errAECoercionFail:
- parameter = kOSAErrorExpectedType;
- paramType = typeType;
- paramData = &expectedType;
- paramSize = sizeof(expectedType);
- break;
-
- case errAEDescNotFound:
- parameter = kOSAErrorOffendingObject;
- paramType = typeKeyword;
- paramData = &key;
- paramSize = sizeof(key);
- break;
-
- }
-
- Throw(err, 0, parameter, paramType, paramData, paramSize);
- }
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::ThrowNILResource() const
- {
- OSErr err = ResError();
-
- Throw(err ? err : resNotFound);
- }
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::ThrowNILResource(
- ResType /* type */,
- short /* resID */) const
- {
- OSErr err = ResError();
-
- Throw(err ? err : resNotFound);
- }
-
- //------------------------------------------------------------------------------
-
-
- /*
- void ThrowErrNum(const LocationInCode& where,
- OSStatus err,
- DescType expectedType,
- DescType actualType,
- AEKeyword key,
- const AEDesc* offendingObject)
- {
- if (err != noErr)
- {
- StdException exc(where, err);
-
- if (expectedType || actualType)
- {
- exc.PutExpectedType(expectedType, actualType);
- }
-
- if (offendingObject)
- {
- exc.PutOffendingObject(*offendingObject);
- }
- else if (key)
- {
- exc.PutOffendingParameter(key);
- }
-
- exc.AboutToThrow();
- throw exc;
- }
- }
- */
-
- //------------------------------------------------------------------------------
-
- OSStatus LocationInCode::LogError(
- OSStatus err) const
- {
- LogError(err, nil);
-
- return err;
- }
-
- //------------------------------------------------------------------------------
-
- OSStatus LocationInCode::LogError(
- OSStatus err,
- const char* msg) const
- {
- Str255 message;
-
- message[0] = '\0';
- AppendToString(message);
-
- DebugWrite("\perror ");
- DebugWriteNum(err);
- DebugWrite("\p, ");
- if (msg)
- {
- DebugWritePtr(msg, strlen(msg));
- }
- DebugWriteLn(message);
-
- return err;
- }
-
- //------------------------------------------------------------------------------
-
- bool LocationInCode::DelegateAECall() const
- {
- SilentException exc(GetLocationInCode(), errAEEventNotHandled);
- exc.AboutToThrow();
- throw exc;
- return false;
- }
-
- //------------------------------------------------------------------------------
-
- #if qDebug
- void LocationInCode::Warning(const char* message) const
- {
- if (message)
- {
- DebugWrite("\pWarning (");
- DebugWrite(message);
- DebugWriteLn("\p).", true);
- }
- else
- {
- DebugWriteLn("\pWarning", true);
- }
- }
-
- void LocationInCode::AssertionFailed(const char* message) const
- {
- if (message)
- {
- DebugWrite("\passertion failed (");
- DebugWrite(message);
- DebugWriteLn("\p).", true);
- }
- else
- {
- DebugWriteLn("\passertion failed.", true);
- }
-
- Throw(eAssertionFailure);
- }
- #endif
-
- //------------------------------------------------------------------------------
-
- void LocationInCode::RequirementNotMet(const char* message) const
- {
- if (message)
- {
- DebugWrite("\prequirement not met (");
- DebugWrite(message);
- DebugWriteLn("\p).", true);
- }
- else
- {
- DebugWriteLn("\prequirement not met.", true);
- }
-
- Throw(eRequirementNotMet);
- }
-
- //------------------------------------------------------------------------------
-
-